Repository navigation
fix(agents): 按完整行双向分页读取会话历史 - #240
Conversation
There was a problem hiding this comment.
Note
Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.
Devin Review found 2 potential issues.
3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| if store | ||
| .read_range( | ||
| &request.agent, | ||
| &request.path, | ||
| ByteRange { | ||
| start: request.size - 1, | ||
| end: request.size, | ||
| }, | ||
| )? | ||
| .is_none() | ||
| { | ||
| return Ok(empty(true, false)); |
There was a problem hiding this comment.
🟡 Resyncs invalidate history cursors silently
After a file is replaced and synced, page checks old cursors against the latest cached revision. An old end cursor can return replacement messages as valid, or a range error after truncation, instead of changed.
Learn more
The host keeps a listed readBytes value while traversing history. sync_file can rebuild the record for the same path, replacing the revision that read_range checks. The paging request carries no identity for the earlier revision. Once the resync completes, the size probe accepts a same-length replacement or errors if the old size exceeds the new cached offset.
Example: Open a 500 KiB history and retain its readBytes. Replace it with a different 500 KiB history at the same path and sync. A backward request from the old end reads the new tail with changed: false, which the host can combine with retained pages from the old file.
Recommended fix: Return a file generation with the listed record and require it on page requests. Keep that generation stable on verified appends and change it on cache rebuilds for replacements or truncations. Validate the generation before reading and return changed on a mismatch.
Was this helpful? React with 👍 or 👎 to provide feedback.
- 长行不再和前面的短行合成一批:加入后会超过约 64 KiB 的行另起一批, 避免合并后的回答超过 1 MiB 函数结果上限而让翻页失败 - 旧 agentSessions.read 不请求工具详情,回答里带详情字段(含显式 null) 时按 agentSessions.invalidRead 拒绝;只有 page 接受 - 会话缓存的文件新增 generation(缓存结构升到 2):文件被替换或截断后 重新读取时换新值;agentSessions.list 回答它,agentSessions.page 必须 带上,不一致时回答 changed,同长度替换也能识别
关联 Issue
Refs 1lck/Lithe-IDEA#2491
问题与修复
较长会话按固定字节范围读取时可能切断记录行,导致部分问答、思考和工具输出无法查看。宿主也缺少从末尾向前读取、淘汰后反向读回的稳定边界。
agentSessions.page,按完整行向前或向后分页,校验授权、来源目录、文件快照和 cursor。changed/tooLong状态。messageIDs: true,接受并校验可选的稳定消息id;旧agentSessions.read与标题读取维持旧的请求和结果形状。API 与兼容性
agentSessions.pageread的可选messageIDs/ 消息idagents能力、plugin API、schema、SDK 包版本均不变。旧插件可忽略messageIDs;旧读取不请求 ID。四语 SDK 的会话来源处理器使用已有 JSON 函数,无新增类型接口。没有新增宿主方法、通知或错误码。此 PR 不包含独立的运行中交互工作。验证
cargo test --manifest-path rust/Cargo.toml -p lithe-agent-runtime:32 项通过。cargo fmt --check、Rust 注释规范:通过。node shared/plugins/scripts/verify-docs.mjs、node scripts/rust-core/verify-platform-tests.mjs:通过。node shared/plugins/scripts/sdk-e2e.mjs:Rust、Go、Node、Java 共 16 项通过。git diff --check:通过。Windows 原生验收与真实 CLI 恢复全流程未运行;跨平台 CI 交给仓库工作流,不把本地组件测试作为整机验收。无发布操作。